import { defineStore } from "pinia";
import { ref } from "vue";
import { UserList, UserDelById } from "@/Service/UserService.js";

export const UserStore = defineStore("UserStore", () => {
  let list = ref([]); //声明了一个集合
  let total = ref(100);

   let initList = async (payload) => {
    let { data } = await UserList(payload);
    list.value = data;
    let res = await UserList({}); //查询总数
    total.value = res.data.list.length; //数据总数
  };
  let delListById = async (payload) => {
    await UserDelById(payload);
    list.value = list.value.filter((item) => item.id !== payload);
  };

  return { list, total, initList, delListById };
});
